package xh.lumt.server.processors;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpResponse;
import xh.lumt.server.PlayStatusRequestManager;
import xh.lumt.server.ServerController;
import xh.lumt.util.HttpUtils;

/**
 * Created by Administrator on 2016/6/30.
 */
public class StatusSyncProcessor extends AbstractProcessor {

    ChannelHandlerContext ctx;
    String uri;

    public StatusSyncProcessor(ChannelHandlerContext ctx, String uri) {
        this.ctx = ctx;
        this.uri = uri;
    }

    public FullHttpResponse process() {

        String[] parts = uri.split("/");
        if (parts == null || parts.length == 0) {
            return HttpUtils._404();
        }

        long lastUpTime;
        try {
            lastUpTime = Long.parseLong(parts[0]);
        } catch (Exception e) {
            return HttpUtils._404();
        }

        PlayStatusRequestManager prm = ServerController.playerStatusRequestHolder();
        prm.requestPlayingStatus(lastUpTime, ctx);
        return null;
    }
}
